package com.xmy.solution.service.impl;

import com.xmy.solution.domain.Categories;
import com.xmy.solution.domain.dto.solution.SolutionAppResDTO;
import com.xmy.solution.domain.dto.userRecommend.UserRecommendDTO;
import com.xmy.solution.mapper.CategoriesMapper;
import com.xmy.solution.mapper.UserRecommendMapper;
import com.xmy.solution.service.IUserRecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class IUserRecommendServiceImpl implements IUserRecommendService {
    @Autowired
    private UserRecommendMapper userRecommendMapper;

    @Autowired
    private CategoriesMapper categoryMapper;
    @Override
    public List<SolutionAppResDTO> selectSolutionAppReqDTOList(Long userId) {
        List<SolutionAppResDTO> list = userRecommendMapper.selectSolutionAppReqDTOList(userId);
        list.forEach(item->{
            item.setCategories(categoryMapper.selectCategoriesBySolutionId(item.getId()));
        });
        return list;
    }

    @Override
    public List<Categories> selectCategoryListByUserId(Long userId) {

        return  userRecommendMapper.selectCategoryListByUserId(userId);
    }

    @Override
    @Transactional
    public int updateSolutions(UserRecommendDTO userRecommendDTO) {
        userRecommendMapper.deleteUserRecommendByUserId(userRecommendDTO.getUserId());
        return userRecommendMapper.insertUserRecommend(userRecommendDTO);
    }
}
